function checkSub(val){
	var gift_name=document.getElementById('gift_name').value;
 
	if(gift_name==''){
		alert('请填写礼品名称');
		document.getElementById('gift_name').focus();
		return false;
	}
	var classstr=document.getElementById("class_attr").value;
	if(setClassStr()==''&&classstr==''){
		alert('请选择礼品分类');
		document.getElementById('sort1').focus();
		return false;
	}
	
	var type=1;
	 
	 
	Ti_giftInfo.getGiftbyIdorName(gift_name,'',type,function(data){
		if(val=='addForm'){
			if(data>0){
				alert("已经有相同的名称存在");
				document.getElementById('gift_name').focus();
			}else{
				document.addForm.submit();
			}
		}else if(val=='updateForm'){ 
			document.updateForm.submit();
		}
	});
	
}

function search(){
	document.indexForm.submit();
}

function isShow(val){
    
	if(val==1){
		document.getElementById("good").style.display="none";
		document.getElementById("stock_num").readOnly=false;
		document.getElementById("gift_type2").checked = false;
	}
	if(val==2){
	    document.getElementById("gift_type1").checked = false;
	    if(isIE()){
		document.getElementById("good").style.display="block";
		}else{
		document.getElementById("good").style.display="";
		}
		document.getElementById("stock_num").readOnly=true;
	}
}
function isIE(){ //ie?
if(window.navigator.userAgent.toLowerCase().indexOf("msie")>=1)   return true;
else    return false;
}

function setClassStr(){
	var sort1="";
	sort1=document.getElementById('sort1').value;
	var sort2="";
	sort2=document.getElementById('sort2').value;
	var str="";
	if(sort1=='') return false;
	if(sort2=='') str=sort1+"|";
	else str=sort1+"|"+sort2+"|";
	document.getElementById('class_attr').value=str;
	return str;
}

function setGood() {
	var str=setClassStr();
	if(str=='')
	{
		alert("请选择礼品类型");
		return false;
	}
	
	if(document.getElementById("good_id").options.length>1){
		document.getElementById("stock_num").value=goodsStocknum();
		return false;
	} 
	
	Ti_goodsInfo.getGoodsByClassAttr(str,function(data){
			DWRUtil.removeAllOptions('good_id');
			DWRUtil.addOptions('good_id',{'':'请选择'});
			DWRUtil.addOptions('good_id',data);
	});
} 

function goodsStocknum(){
			var goods="";
			var str="";
			var stocknum=0;
			var val=document.getElementById("good_id");
            for(i=0;i<val.length;i++){   
                if(val.options[i].selected){
                	str=val.options[i].text;
                	stocknum +=parseInt(str.substring(str.indexOf("|")+1,str.length));
                }
            }
       return stocknum;
}
